import go from 'gojs'

const KAPPA = 4 * ((Math.sqrt(2) - 1) / 3)

const orGate = go.Shape.defineFigureGenerator('OrGate', function (shape, w, h) {
  var geo = new go.Geometry()
  var radius = 0.5
  var cpOffset = KAPPA * radius
  var centerx = 0
  var centery = 0.5
  var fig = new go.PathFigure(0, 0, true)
  geo.add(fig)

  fig.add(new go.PathSegment(go.PathSegment.Bezier, w, 0.5 * h, (centerx + cpOffset + cpOffset) * w, (centery - radius) * h,
    0.8 * w, (centery - cpOffset) * h))
  fig.add(new go.PathSegment(go.PathSegment.Bezier, 0, h, 0.8 * w, (centery + cpOffset) * h,
    (centerx + cpOffset + cpOffset) * w, (centery + radius) * h))
  fig.add(new go.PathSegment(go.PathSegment.Bezier, 0, 0, 0.25 * w, 0.75 * h, 0.25 * w, 0.25 * h).close())
  geo.spot1 = new go.Spot(0.2, 0.25)
  geo.spot2 = new go.Spot(0.75, 0.75)
  return geo
})
const andGate = go.Shape.defineFigureGenerator('AndGate', function (shape, w, h) {
  var geo = new go.Geometry()
  var cpOffset = KAPPA * 0.5
  var fig = new go.PathFigure(0, 0, true)
  geo.add(fig)

  // The gate body
  fig.add(new go.PathSegment(go.PathSegment.Line, 0.5 * w, 0))
  fig.add(new go.PathSegment(go.PathSegment.Bezier, w, 0.5 * h, (0.5 + cpOffset) * w, 0,
    w, (0.5 - cpOffset) * h))
  fig.add(new go.PathSegment(go.PathSegment.Bezier, 0.5 * w, h, w, (0.5 + cpOffset) * h,
    (0.5 + cpOffset) * w, h))
  fig.add(new go.PathSegment(go.PathSegment.Line, 0, h).close())
  geo.spot1 = go.Spot.TopLeft
  geo.spot2 = new go.Spot(0.55, 1)
  return geo
})
export { orGate, andGate }
